<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class StockReward extends Model
{   
    protected $table = 'stock_rewards';
    //
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'stock_activity_id',
        'user_id',
        'stock_order_id',
        'money',
        'level',
        'partner_trade_no',
        'transaction_id',
        'payment_time',
        'note',
        'status'
    ];

   public function order(){
        return $this->belongsTo('App\Models\StockOrder','stock_order_id');
    }

    protected static function count_money($id)
    {
        $total_price=self::where(['stock_activity_id'=>$id])->sum('money');
        return $total_price;
    }

    protected static function find_winning($uid)
    {
        $winning=self::where(['user_id'=>$uid])->paginate(8);
        return $winning;
    }

}
